package com.flnet.spsys.config;

import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.util.Properties;

@Component
public class KaptcharConfig {

    final String KAPTCHA_BORDER = "kaptcha.border";
    final String KAPTCHA_BORDER_COLOR = "kaptcha.border.color";
    final String KAPTCHA_TEXTPRODUCER_FONT_COLOR = "kaptcha.textproducer.font.color";
    final String KAPTCHA_IMAGE_WIDTH = "kaptcha.image.width";
    final String KAPTCHA_IMAGE_HEIGHT = "kaptcha.image.height";
    final String KAPTCHA_TEXTPRODUCER_FONT_SIZE = "kaptcha.textproducer.font.size";
    final String KAPTCHA_SESSION_KEY = "kaptcha.session.key";
    final String KAPTCHA_TEXTPRODUCER_CHAR_LENGTH = "kaptcha.textproducer.char.length";
    final String KAPTCHA_TEXTPRODUCER_FONT_NAMES = "kaptcha.textproducer.font.names";
    final String KAPTCHA_NOISE_COLOR = "kaptcha.noise.color";
    final String KAPTCHA_OBSCURIFICATOR_IMPL = "kaptcha.obscurificator.impl";
    final String KAPTCHA_TEXTPRODUCER_CHAR_STRING = "kaptcha.textproducer.char.string";
    @Bean
    public DefaultKaptcha getDefaultKaptcha() {
        DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
        Properties properties = new Properties();
        properties.setProperty(KAPTCHA_BORDER, "yes");
        properties.setProperty(KAPTCHA_BORDER_COLOR, "220,220,220");
        properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_COLOR, "38,29,12");
        properties.setProperty(KAPTCHA_IMAGE_WIDTH, "147");
        properties.setProperty(KAPTCHA_IMAGE_HEIGHT, "34");
        properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_SIZE, "25");
        properties.setProperty(KAPTCHA_SESSION_KEY, "code");
        properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_LENGTH, "4");
        properties.setProperty(KAPTCHA_TEXTPRODUCER_FONT_NAMES, "Arial");
        properties.setProperty(KAPTCHA_NOISE_COLOR, "164,128,55");
        properties.setProperty(KAPTCHA_OBSCURIFICATOR_IMPL, "com.google.code.kaptcha.impl.ShadowGimpy");
        properties.setProperty(KAPTCHA_TEXTPRODUCER_CHAR_STRING, "0123456789");
        Config config = new Config(properties);
        defaultKaptcha.setConfig(config);
        return defaultKaptcha;
    }
}